package org.example.controller;

import cn.dev33.satoken.util.SaResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
import org.example.domain.vo.LoginResultVo;
import org.example.service.domain.RestAuthService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.IOException;


@Slf4j
@RestController
@RequestMapping("/thirdParity")
@Api(value = "RestAuthController",tags = {"第三方登录"})
@Validated
public class RestAuthController {
    @Resource
    private RestAuthService restAuthService;
    

    @RequestMapping("/callback/{socialCode}/{loginType}")
    @ApiOperation(value = "三方登录回调接口")
    public SaResult callback(@ApiParam("认证回调接口")  AuthCallback callback,
                             @ApiParam("社交码") @PathVariable("socialCode")String socialCode,
                             @ApiParam("登录类型") @PathVariable Integer loginType) {
        LoginResultVo resultVo =  restAuthService.callback(callback, socialCode,loginType);
        return SaResult.ok().setData(resultVo);
    }

    /**
     * 
     * @param socialCode 
     * @see org.example.enmus.SocialAuthEnum
     * @param loginType
     * @see org.example.enmus.LoginTypeEnum
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "获取第三方认证链接")
    @RequestMapping("/render")
    public SaResult renderAuth(@ApiParam(name = "socialCode", value = "社交码", required = true,example = "1")
                               @NotBlank(message = "社交码不能为空") String socialCode,
                               @ApiParam(value = "登录类型", required = true,example = "3") @NotNull(message = "登录类型不能为空") Integer loginType
    ) throws IOException {
        return SaResult.ok().setData(restAuthService.getAuthLinkUrl(socialCode, loginType));
    }

  
    
    
}